package com.hualidianping.interceptor;

import com.hualidianping.dto.UserDTO;
import com.hualidianping.utils.UserHolder;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //1.判断是否需要拦截(ThreadLocal是否有用户)
        if(UserHolder.getUser()==null){
            response.setStatus(401);
            return false;
        }
        //有用户则放行
        return true;
    }
}
